#ifndef __CUTILS_H__
#define __CUTILS_H__

#include <string>

class CUtils
{
public:

	//=============================================================================
	//! Compute SHA1 of text file
	//!
	//! \param	filename	Name of text file
	//!
	//! \return The computed SHA1 in text form
	//=============================================================================
	static std::string sha1(const char* const filename);

	//=============================================================================
	//! Encrypt text buffer using private key
	//!
	//! \param	key_filename	Private key
	//! \param	buffer			Input buffer
	//!
	//! \return	The encrypted buffer in base64 encoding
	//=============================================================================
	static std::string encryptPrivateKey(const char* const key_filename, const std::string& buffer);

	//=============================================================================
	//! Decrypt buffer using public key
	//!
	//! \param	key_filename	Public key
	//! \param	buffer			Input buffer is encryptd using private key
	//!
	//!	\note	The buffer must be in base64 encoding
	//!
	//! \return	The computed SHA1 in text form
	//=============================================================================
	static std::string decryptPublicKey(const char* const key_filename, const std::string& buffer);

	//=============================================================================
	//! Create a new file contained sign of the input file
	//!
	//! \param	filename		Input file
	//! \param	private_key		Private key

	//!	\note	The file of sign has suffix ".sign.xml"
	//!
	//! \return	true on success, otherwise false
	//=============================================================================
	static bool sign(const char* const filename, const char* const private_key);

	//=============================================================================
	//! Validate sign of input file
	//!
	//! \param	filename		Input file(not file *.sign.xml)
	//! \param	public_key		Public key
	//!
	//! \return	true on success, otherwise false
	//=============================================================================
	static bool validateSign(const char* const filename, const char* const public_key);

	static void encodeBase64(const std::string& in, std::string& out);
	static void decodeBase64(const std::string& in, std::string& out);
	static std::string str2bin(const char* hex);
	static size_t getFileSize(FILE* file);

private:
	CUtils();
};

#endif